﻿using SqlSugar;

namespace Hospital.Utility.ApiResult
{
    public class ApiResultHelper
    {
        /// <summary>
        /// 成功返回
        /// </summary>
        /// <param name="data"></param>
        /// <returns>响应参数</returns>
        public static ApiResult Success(dynamic data)
        {
            return new ApiResult
            {
                Code = 200,
                Message = "OK",
                Total = 0,
                Data = data
            };
        }
        public static ApiResult Success(string msg, dynamic data)
        {
            return new ApiResult
            {
                Code = 200,
                Message = msg,
                Total = 0,
                Data = data
            };
        }
        /// <summary>
        /// 成功返回
        /// </summary>
        /// <param name="data">数据</param>
        /// <param name="total">数据量</param>
        /// <returns>响应参数</returns>
        public static ApiResult Success(dynamic data, RefAsync<int> total)
        {
            return new ApiResult
            {
                Code = 200,
                Message = "success",
                Total = total,
                Data = data
            };
        }
        public static ApiResult Error(dynamic data)
        {
            return new ApiResult
            {
                Code = 500,
                Message = "error",
                Total = 0,
                Data = data
            };
        }
        public static ApiResult Error(string message)
        {
            return new ApiResult
            {
                Code = 500,
                Message = message,
                Total = 0,
                Data = null
            };
        }
        public static ApiResult Error(int code, string message)
        {
            return new ApiResult
            {
                Code = code,
                Message = message,
                Total = 0,
                Data = null
            };
        }
    }
}
